<?php
/**
 * Created by dzw.
 * User: Administrator
 * Date: 2018-03-16
 * Time: 10:22
 */

namespace App\Http\Controllers\Admin\Report;

use App\Http\Controllers\Admin\BaseController;
use App\Http\Middleware\RedirectIfAuthenticated;
use Illuminate\Http\Request;


class TypeController extends BaseController
{
    protected $api_url = [
        'list' => ['get', 'report/type'],//举报类型列表
        'create' => ['post', 'report/type'],//创建举报类型
        'delete' => ['delete', 'report/type/%d'],//删除举报类型
    ];
    protected $api_host;

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->api_host = config('url.api_backend');
    }

    public function indexAction()
    {
        //参数部分
        $search_params = $this->request->all(['name','create_at','status']);
        $page = $this->request->get('page', 1);
        $params = [
            'search' => search_params($search_params),
            'searchJoin' => 'and',
            'page' => $page
        ];

        //请求部分
        $ret = http_admin($this->api_url['list'])->send($params);

        //结果处理部分
        $this->httpCodeJudge($ret);
        $data = paginate($this->request, $ret['data']);

        //回填搜索框值
        $data['search_params'] = $search_params;

        return view('Admin.report.type', $data);
    }
    public function createAction(){
        //参数部分
        $params = $this->request->all(['name','content','status']);

        //请求部分
        $ret = http_admin($this->api_url['create'])->send($params);
        $ret=$this->httpCodeJudge($ret);
        if($ret){
            return redirect('foradmin/report/type');
        }else{
            return redirect('foradmin/404');
        }

    }

    public function deleteAction()
    {
        $id = $this->request->post('id');
        $ret = http_admin($this->api_url['delete'],[$id])->send();
        return $ret;
    }


}